package cn.itcast.star.graph.core.service.impl;

import cn.itcast.star.graph.comfyui.client.pojo.ComfyuiModel;
import cn.itcast.star.graph.core.service.FreemarkerService;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import freemarker.template.Configuration;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;

@Service
public class FreemarkerServiceImpl implements FreemarkerService {

    @Autowired
    private Configuration configuration;

    @Override
    public String renderText2Image(ComfyuiModel comfyuiModel) throws IOException, TemplateException {
        Template template = configuration.getTemplate("t2i.ftlh");
        StringWriter stringWriter = new StringWriter();
        template.process(Map.of("config", comfyuiModel), stringWriter);
        return stringWriter.toString();
    }
}
